﻿using Sunny.UI;
using System.Collections.Generic;
using CoreShop.Model;
using CoreShop.Services;
using System;
using CoreShop.Model.UI;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Collections;
using System.Security.Policy;
using SqlSugar.Extensions;
using Sunny.UI.Win32;
using System.Windows.Forms;
using System.ComponentModel;
using CoreShop.Library;
using System.Data;
using FastMember;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System.IO;
using System.Linq;

namespace CoreShop.App
{
    public partial class FrmUserSelect : UIForm
    {
        public corecmsuser memberSelect = null;
        public List<corecmsuser> memberList = null;

        public FrmUserSelect(List<corecmsuser> _memberList = null)
        {
            memberList = _memberList;
            InitializeComponent();
        }
        public FrmUserSelect()
        {
            InitializeComponent();
        }
        
        private void FMember_Load(object sender, System.EventArgs e)
        {
            this.dgvMemberList.AutoGenerateColumns = false;
            this.dgvMemberList.DataSource = memberList;
        }            

        private void dgvMemberList_CellDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            btnSelect_Click(null, null);
        }
              
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (dgvMemberList.CurrentRow != null)
            {
                long MemberId = CommFunc.ConvertToInt64(dgvMemberList.CurrentRow.Cells["id"].Value);
                memberSelect = memberList.Where(x => x.id == MemberId).FirstOrDefault();
                if (memberSelect != null)
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
            else
            {
                UIMessageBox.Show("没有选择会员信息，无法返回。");
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void dgvMemberList_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13) btnSelect_Click(null, null);
        }
    }
}